package com.llmm.eduService.controller;

import com.llmm.aspect.SysControllerLog;
import com.llmm.bean.RestRet;
import com.llmm.eduService.entity.EduSubject;
import com.llmm.eduService.entity.EduSubjectTree;
import com.llmm.eduService.service.EduSubjectService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @description: 课程分类接口
 * @author: llmm
 * @date: 2022/3/13
 */
@RestController
@RequestMapping("edu/subject")
@Slf4j
@CrossOrigin
public class EduSubjectController {
    @Autowired
    private EduSubjectService eduSubjectService;

    /**
     * @description: 查询所有课程信息
     * @param:
     * @return: List<EduSubject>
     * @author: llmm
     * @date: 2022/2/21
     */
    @SysControllerLog
    @GetMapping("/queryAll")
    public RestRet<List> findAll(){
        List<EduSubject> list = eduSubjectService.findAllSubjects();
        int total = list.size();
        return new RestRet<>(list,total,null);
    }


    /**
     * @description: 查询父类和子类的课程
     * @param:
     * @return: java.util.List
     * @author: llmm
     * @date: 2022/2/21
     */
    @GetMapping("/queryAllByTree")
    public RestRet<List> findAllBYTree(){
        List<EduSubjectTree> list = eduSubjectService.findAllTrees();
        int total = list.size();
        return new RestRet<>(list,total,null);
    }

    //查询所有一级分类
    @GetMapping("/queryAllRoot")
    public RestRet<List> findAllRoot(){
        List<EduSubject> list = eduSubjectService.findAllRoot();
        return new RestRet<>(list,0,null);
    }

    //根据一级分类查询二级分类
    @GetMapping("/queryLeafByRoot/{id}")
    public RestRet<List> findLeaf(@PathVariable String id){
        List<EduSubject> list = eduSubjectService.findLeafByRoot(id);
        return new RestRet<>(list,0,null);
    }

    //查询所有一级分类的二级分类的个数。
    @GetMapping("/queryChart")
    public RestRet<Map> findChart(){
        Map chart = eduSubjectService.findChart();
        return new RestRet<>(chart,0,null);
    }



}
